package cn.liziguo.tank.buff;

import cn.liziguo.tank.constants.ImageConst;
import cn.liziguo.tank.script.BaseTankComponent;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.dsl.components.Effect;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.texture.Texture;
import javafx.util.Duration;
import org.jetbrains.annotations.NotNull;

/**
 * @author Liziguo
 * @date 2022-07-14 22:34:21
 */
public class ShipEffect extends Effect {

    private BaseTankComponent tankComponent;
    private Texture texture;

    public ShipEffect() {
        super(Duration.INDEFINITE);
    }

    @Override
    public void onEnd(@NotNull Entity entity) {
        entity.getViewComponent().removeChild(texture);
        tankComponent.isArmedShip = false;
    }

    @Override
    public void onStart(@NotNull Entity entity) {
        tankComponent = BaseTankComponent.getTankComponent(entity);
        tankComponent.isArmedShip = true;
        Texture imageView = FXGL.texture(ImageConst.ARMED_SHIP);
        imageView.setTranslateX(entity.getWidth() / 2 - imageView.getWidth() / 2);
        imageView.setTranslateY(entity.getHeight() / 2 - imageView.getHeight() / 2);
        entity.getViewComponent().addChild(imageView);
        texture = imageView;
    }
}
